package interfaz;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class EliminarProyecto extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private static String title=new String("Eliminar proyecto");
	private JButton okButton;
	private JButton cancelButton;
	private JLabel lblProyectos;
	private JList<String> list;

	/**
	 * Create the dialog.
	 */
	public EliminarProyecto(JFrame parent,String[] s) {
		super(parent,title,true);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			okButton = new JButton("OK");
			okButton.addActionListener(new ActionListener()	{

				@Override
				public void actionPerformed(ActionEvent e) {
					//list = new JList();
					dispose();
				}		
			});
			okButton.setActionCommand("OK");
			getRootPane().setDefaultButton(okButton);
		}
		{
			cancelButton = new JButton("Cancel");
			cancelButton.addActionListener(new ActionListener()	{

				@Override
				public void actionPerformed(ActionEvent e) {
					list = new JList();
					dispose();
				}		
			});
			
			addWindowListener(new WindowAdapter() {
			    
			    public void windowClosing(WindowEvent e) {
			    	list = new JList();
					dispose();
			    }
			});
			
			cancelButton.setActionCommand("Cancel");
		}
		lblProyectos = new JLabel("Proyectos :");
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
						.addComponent(lblProyectos)
						.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
							.addComponent(okButton)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(cancelButton)))
					.addContainerGap())
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblProyectos)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(okButton)
						.addComponent(cancelButton))
					.addContainerGap())
		);
		
		list = new JList<String>();
		list.setListData(s);
		scrollPane.setViewportView(list);
		contentPanel.setLayout(gl_contentPanel);
		setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
		setVisible(true);
	}
	
	public int getSelectedIndex()
	{
		return list.getSelectedIndex();
	}
	
	public String getSelectedValue()
	{
		return list.getSelectedValue();
	}
}
